package com.muyu.system.danmo.controller;

import com.muyu.common.core.enums.PayChannel;
import com.muyu.system.danmo.service.PayService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * @author Administrator
 */
@Slf4j
@RestController
@RequestMapping("/open/api/alipay/callback")
@RequiredArgsConstructor
public class AliPayCallBackController {

    private final PayService payService;

    /**
     * 支付宝的回调地址
     */
    @PostMapping("/payNotify/{mchCode}/{payChannel}")
    public String payNotify(HttpServletRequest request, @PathVariable String mchCode, @PathVariable PayChannel payChannel) {
        log.info("支付宝回调参数：{}，{}", mchCode, payChannel);
        try {
            payService.payNotify(request, payChannel, mchCode);
            return "success";
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return "fail";
        }
    }



}
